<%@page import="com.muk.meis.model.service.report.ReportByOPEC"%>
<%@page import="java.text.DecimalFormat"%>
<%@page import="java.text.NumberFormat"%>
<%@page import="java.util.List"%>
<%@page import="java.util.Iterator"%>
<%@page import="java.util.EnumSet"%>
<%@page import="com.muk.meis.MEISConstance.DISTRICT"%>
<%@page import="com.muk.meis.model.service.ReportService"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>MEIS</title>
<!--[if lte IE 8]><script language="javascript" type="text/javascript" src="js/flot/excanvas.min.js"></script><![endif]-->
<link href="css/dropdown/themes/default/helper.css" media="screen" rel="stylesheet" type="text/css" />
<!-- Beginning of compulsory code below -->

<link href="css/dropdown/dropdown.css" media="screen" rel="stylesheet" type="text/css" />
<link href="css/dropdown/themes/default/default.css" media="screen" rel="stylesheet" type="text/css" />

<link type="text/css" href="css/redmond/jquery-ui-1.8.16.custom.css" rel="stylesheet" />	
<script type="text/javascript" src="js/jquery/jquery.js"></script>
<script type="text/javascript" src="js/jquery/jquery-ui-1.8.16.custom.min.js"></script>

<!--[if lt IE 7]>
<script type="text/javascript" src="js/jquery/jquery.js"></script>
<script type="text/javascript" src="js/jquery/jquery.dropdown.js"></script>
<![endif]-->

<!-- / END -->
<script language="javascript" type="text/javascript"
	src="js/flot/jquery.flot.js"></script>
<style type="text/css">
.mesi_header_m {
	color: #F00;
}
</style>

<link href="css/meis.css" rel="stylesheet" type="text/css">
</head>
<body>
	<form>     
       <jsp:include page="menu.jsp"></jsp:include>
              
       <div style="position:relative;padding-top: 60px; padding-left:450px;">
                                      ปีการศึกษา
          <select>
               <option>2554</option>
               <option>2553</option>
          </select>
          <input type="button" class="button" value="ค้นหา">
       </div>      
       
       <div>
			<script type="text/javascript">
				$(function(){
		
	
					// Dialog			
					$('#dialog').dialog({
						autoOpen: false,
						width: 700,
						height: 550,
						buttons: {
							"Ok": function() { 
								$(this).dialog("close"); 
							}, 
							"Cancel": function() { 
								$(this).dialog("close"); 
							} 
						}
					});
					
					// Dialog Link
					$('#dialog_link').click(function(){
						$('#dialog').dialog('open');
						return false;
					});
					
					//hover states on the static widgets
					$('#dialog_link, ul#icons li').hover(
						function() { $(this).addClass('ui-state-hover'); }, 
						function() { $(this).removeClass('ui-state-hover'); }
					)
					
				});
			</script>       
			<style type="text/css">
				#dialog_link {padding: .4em 1em .4em 20px;text-decoration: none;position: relative;}
				#dialog_link span.ui-icon {margin: 0 5px 0 0;position: absolute;left: .2em;top: 50%;margin-top: -8px;}
				ul#icons {margin: 0; padding: 0;}
				ul#icons li {margin: 2px; position: relative; padding: 4px 0; cursor: pointer; float: left;  list-style: none;}
				ul#icons span.ui-icon {float: left; margin: 0 4px;}
			</style>
				<p>
				<a href="#" id="dialog_link" class="ui-state-default ui-corner-all">
					<span class="ui-icon ui-icon-newwin"></span>แสดงกราฟ
				</a>
				</p>
				
	            <!-- ui-dialog -->
				<div id="dialog" title="กราฟ">	
					<!-- amcharts script-->
					<!-- swf object (version 2.2) is used to detect if flash is installed and include swf in the page -->
					<script type="text/javascript" src="amcharts/flash/swfobject.js"></script>
			
					<!-- chart is placed in this div. if you have more than one chart on a page, give unique id for each div -->
					<div id="pie"></div>
				        <%
				        ReportByOPEC reportByOPEC = new ReportByOPEC();
					    String xmlOPEC = reportByOPEC.getXMLDataGraph();
						System.out.println(xmlOPEC);
				        %> 
					    <script type="text/javascript">
					    
				            var params = {
				                bgcolor:"#FFFFFF"
				                };
				
						    var flashVars = {
						        path: "amcharts/flash/",
						        chart_settings: encodeURIComponent("<settings><background><alpha>100</alpha><border_alpha>20</border_alpha></background><legend><enabled>0</enabled><align>center</align></legend><pie><y>50%</y><inner_radius>30</inner_radius></pie><animation><start_time>2</start_time><start_effect>strong</start_effect><pull_out_time>1.5</pull_out_time></animation><data_labels><show>{title}: {value}</show><max_width>140</max_width></data_labels></settings>"),
						        //settings_file: "test/settings.xml",
				                //chart_data: encodeURIComponent("<pie><slice title='United States'>19544</slice><slice title='Japan'>5455</slice><slice title='Unresolved'>4229</slice><slice title='France'>2313</slice><slice title='Germany'>2208</slice><slice title='United Kingdom'>2057</slice><slice title='India'>1771</slice><slice title='Russian Federation'>1495</slice><slice title='Korea, Republic of'>1281</slice></pie>"),
				                chart_data: encodeURIComponent("<%=xmlOPEC%>"),
						        chart_id:"pie"
							};
				
					    	swfobject.embedSWF("amcharts/flash/ampie.swf", "pie", "600", "400", "8.0.0", "amcharts/flash/expressInstall.swf", flashVars, params);
				 
				        </script>
				 </div>
       </div>
              
       <div style="position:relative;padding-top: 20px;">
       	<table border="1" width="1224px;" cellspacing="0px;" bordercolor="#CCCCCC">
       	    <caption style="position: relative;padding-bottom: 20px;">ตารางแสดงจำนวนห้องเรียน  นักเรียนแยก ชาย หญิง  จำแนกรายอำเภอ ปีการศึกษา  2554 (ข้อมูล  10 มิ.ย.54)</caption> 
       		<tr bordercolor="#CCCCCC" bgcolor="#ADFF5B" align="center">
       			<td rowspan="2">ที่</td>
       			<td align="center" rowspan="2">อำเภอ</td>
       			
       			<td align="center" colspan="2">อ.1</td>
       			<td align="center" colspan="2">อ.2</td>
       			<td align="center" colspan="2">รวม อ.</td>
       			
       			<% for(int i=1;i<=6;i++){ %>
       			 <td colspan="2"><%="ป."+i%></td>
       			<% } %>
       			<td align="center" colspan="2">รวมประถม</td>
       			
       			<% for(int i=1;i<=3;i++){ %>
       			 <td align="center" colspan="2"><%="ป."+i%></td>
       			<% } %>
       			<td align="center" colspan="2">รวม ม.ต้น</td>       			
       			<td align="center" colspan="4">รวมทั้งสิ้น</td>       			
       		</tr>
       		<tr bordercolor="#CCCCCC" bgcolor="#ADFF5B">
       		   <% for(int i=1;i<=2;i++){ %>
       			    <td align="center">ชาย</td>
       			    <td align="center">หญิง</td>
       			<% } %>
       			<td align="center" style="color:#F00">รวม</td>
       			<td align="center">ห้อง</td>
       			
       		   <% for(int i=1;i<=6;i++){ %>
       			    <td align="center">ชาย</td>
       			    <td align="center">หญิง</td>
       			<% } %>
       			<td align="center" style="color:#F00">รวม</td>
       			<td align="center">ห้อง</td>
       			
       		   <% for(int i=1;i<=3;i++){ %>
       			    <td align="center">ชาย</td>
       			    <td align="center">หญิง</td>
       			<% } %>
       			<td align="center" style="color:#F00">รวม</td>
       			<td align="center">ห้อง</td>   
       			
       			<td align="center">ชาย</td>  
       			<td align="center">หญิง</td>  
       			<td align="center">รวม</td>  
       			<td align="center">ห้อง</td>  
       			    			
       		</tr>
		   <%
		   ReportService service = new ReportService();
		   int couter = 1;
		   NumberFormat formatter = new DecimalFormat("###,###,###");
		   Integer sumKindergartenMan1 = 0;
		   Integer sumKindergartenGirl1 = 0;
		   Integer sumKindergartenMan2 = 0;
		   Integer sumKindergartenGirl2 = 0;
		   Integer sumKindergarten = 0;
		   Integer sumKindergartenRoom = 0;
		   
		   Integer sumPrimaryEducationMan1 = 0;
		   Integer sumPrimaryEducationMan2 = 0;
		   Integer sumPrimaryEducationMan3 = 0;
		   Integer sumPrimaryEducationMan4 = 0;
		   Integer sumPrimaryEducationMan5 = 0;
		   Integer sumPrimaryEducationMan6 = 0;		   
		   Integer sumPrimaryEducationGirl1 = 0;
		   Integer sumPrimaryEducationGirl2 = 0;
		   Integer sumPrimaryEducationGirl3 = 0;
		   Integer sumPrimaryEducationGirl4 = 0;
		   Integer sumPrimaryEducationGirl5 = 0;
		   Integer sumPrimaryEducationGirl6 = 0;
		   Integer sumPrimaryEducation = 0;
		   Integer sumPrimaryEducationRoom = 0;
		   
		   Integer sumHighSchoolMan1 = 0;
		   Integer sumHighSchoolMan2 = 0;
		   Integer sumHighSchoolMan3 = 0;		   
		   Integer sumHighSchoolGirl1 = 0;
		   Integer sumHighSchoolGirl2 = 0;
		   Integer sumHighSchoolGirl3 = 0;
		   Integer sumHighSchool = 0;
		   Integer sumHighSchoolRoom = 0;
		   
		   for(DISTRICT district:EnumSet.allOf(DISTRICT.class)) {
		        Object[] mangReport = service.getReportForOPEC(district);
		        
		        Integer kindergartenMan1 = Integer.parseInt(mangReport[1].toString());
		        Integer kindergartenGirl1 = Integer.parseInt(mangReport[2].toString());
		        sumKindergartenMan1 += kindergartenMan1;
		        sumKindergartenGirl1 += kindergartenGirl1;		        
		        Integer kindergartenMan2 = Integer.parseInt(mangReport[3].toString());
		        Integer kindergartenGirl2 = Integer.parseInt(mangReport[4].toString());
		        sumKindergartenMan2 += kindergartenMan2;
		        sumKindergartenGirl2 += kindergartenGirl2;		        
		        Integer kindergarten = Integer.parseInt(mangReport[5].toString());
		        sumKindergarten += kindergarten;		        
		        Integer kindergartenRoom = Integer.parseInt(mangReport[6].toString());
		        sumKindergartenRoom += kindergartenRoom;
		        
		        Integer primaryEducationMan1 = Integer.parseInt(mangReport[7].toString());
		        sumPrimaryEducationMan1 += primaryEducationMan1;		        
		        Integer primaryEducationGirl1 = Integer.parseInt(mangReport[8].toString());
		        sumPrimaryEducationGirl1 += primaryEducationGirl1;
		        
		        Integer primaryEducationMan2 = Integer.parseInt(mangReport[9].toString());
		        sumPrimaryEducationMan2 += primaryEducationMan2;		        
		        Integer primaryEducationGirl2 = Integer.parseInt(mangReport[10].toString());
		        sumPrimaryEducationGirl2 += primaryEducationGirl2;
		        
		        Integer primaryEducationMan3 = Integer.parseInt(mangReport[11].toString());
		        sumPrimaryEducationMan3 += primaryEducationMan3;		        
		        Integer primaryEducationGirl3 = Integer.parseInt(mangReport[12].toString());
		        sumPrimaryEducationGirl3 += primaryEducationGirl3;
		        
		        Integer primaryEducationMan4 = Integer.parseInt(mangReport[13].toString());
		        sumPrimaryEducationMan4 += primaryEducationMan4;		        
		        Integer primaryEducationGirl4 = Integer.parseInt(mangReport[14].toString());
		        sumPrimaryEducationGirl4 += primaryEducationGirl4;
		        
		        Integer primaryEducationMan5 = Integer.parseInt(mangReport[15].toString());
		        sumPrimaryEducationMan5 += primaryEducationMan5;		        
		        Integer primaryEducationGirl5 = Integer.parseInt(mangReport[16].toString());
		        sumPrimaryEducationGirl5 += primaryEducationGirl5;
		        
		        Integer primaryEducationMan6 = Integer.parseInt(mangReport[17].toString());
		        sumPrimaryEducationMan6 += primaryEducationMan6;		        
		        Integer primaryEducationGirl6 = Integer.parseInt(mangReport[18].toString());
		        sumPrimaryEducationGirl6 += primaryEducationGirl6;
		        
		        Integer primaryEducation =Integer.parseInt(mangReport[19].toString());
		        sumPrimaryEducation += primaryEducation;
		        Integer primaryEducationRoom = Integer.parseInt(mangReport[20].toString());
		        sumPrimaryEducationRoom += primaryEducationRoom;		        
		        
		        
		        Integer highSchoolMan1 = Integer.parseInt(mangReport[21].toString());
		        sumHighSchoolMan1 += highSchoolMan1;
		        Integer highSchoolGirl1 =  Integer.parseInt(mangReport[22].toString());
		        sumHighSchoolGirl1 += highSchoolGirl1;
		        
		        Integer highSchoolMan2 = Integer.parseInt(mangReport[23].toString());
		        sumHighSchoolMan2 += highSchoolMan2;
		        Integer highSchoolGirl2 =  Integer.parseInt(mangReport[24].toString());
		        sumHighSchoolGirl2 += highSchoolGirl2;		
		        
		        Integer highSchoolMan3 = Integer.parseInt(mangReport[25].toString());
		        sumHighSchoolMan3 += highSchoolMan3;
		        Integer highSchoolGirl3 =  Integer.parseInt(mangReport[26].toString());
		        sumHighSchoolGirl3 += highSchoolGirl3;			        
		        
		        Integer highShool = Integer.parseInt(mangReport[27].toString());
		        sumHighSchool += highShool;
		        Integer highShoolRoom = Integer.parseInt(mangReport[28].toString());
		        sumHighSchoolRoom += highShoolRoom;
		        
		    %>       		
       		<tr bordercolor="#CCCCCC" align="right">
       		   <td bgcolor="#ADFF5B"><%=couter++%></td>
	           <td align="left" bgcolor="#ADFF5B"><%=mangReport[0]%></td>
	           
	           <td><%=formatter.format(kindergartenMan1)%></td>
	           <td><%=formatter.format(kindergartenGirl1)%></td>
	           
	           <td><%=formatter.format(kindergartenMan2)%></td>
	           <td><%=formatter.format(kindergartenGirl2)%></td>
	           
	           <td style="color:#F00"><%=formatter.format(kindergarten)%></td>
	           <td><%=formatter.format(sumKindergartenRoom)%></td>
	           
	           <td><%=formatter.format(primaryEducationMan1)%></td>
	           <td><%=formatter.format(primaryEducationGirl1)%></td>
	           
	           <td><%=formatter.format(primaryEducationMan2)%></td>
	           <td><%=formatter.format(primaryEducationGirl2)%></td>
	           
	           <td><%=formatter.format(primaryEducationMan3)%></td>
	           <td><%=formatter.format(primaryEducationGirl3)%></td>
	           
	           <td><%=formatter.format(primaryEducationMan4)%></td>
	           <td><%=formatter.format(primaryEducationGirl4)%></td>
	           
	           <td><%=formatter.format(primaryEducationMan5)%></td>
	           <td><%=formatter.format(primaryEducationGirl5)%></td>

	           <td><%=formatter.format(primaryEducationMan6)%></td>
	           <td><%=formatter.format(primaryEducationGirl6)%></td>
	           
	           <td style="color:#F00"><%=formatter.format(primaryEducation)%></td>
	           <td><%=formatter.format(primaryEducationRoom)%></td>
	           
	           <td><%=formatter.format(highSchoolMan1)%></td>
	           <td><%=formatter.format(highSchoolGirl1)%></td>
	           
	           <td><%=formatter.format(highSchoolMan2)%></td>
	           <td><%=formatter.format(highSchoolGirl2)%></td>
	           
	           <td><%=formatter.format(highSchoolMan3)%></td>
	           <td><%=formatter.format(highSchoolGirl3)%></td>
	           
	           <td style="color:#F00"><%=formatter.format(highShool)%></td>
	           <td><%=formatter.format(highShoolRoom)%></td>	 
	           
	           <td><%=formatter.format(kindergartenMan1+kindergartenMan2+
	        		                   primaryEducationMan1+primaryEducationMan2+primaryEducationMan3+
	        		                   primaryEducationMan4+primaryEducationMan5+primaryEducationMan6+
	        		                   highSchoolMan1+highSchoolMan2+highSchoolMan3
	        		                   )%></td>
	           <td><%=formatter.format(kindergartenGirl1+kindergartenGirl2+
	        		                   primaryEducationGirl1+primaryEducationGirl2+primaryEducationGirl3+
	        		                   primaryEducationGirl4+primaryEducationGirl5+primaryEducationGirl6+
	        		                   highSchoolGirl1+highSchoolGirl2+highSchoolGirl3
	        		                   )%></td>   
	        		                          	                     
	           <td style="color:#F00"><%=formatter.format(kindergartenMan1+kindergartenMan2+
	        		                   primaryEducationMan1+primaryEducationMan2+primaryEducationMan3+
	        		                   primaryEducationMan4+primaryEducationMan5+primaryEducationMan6+
	        		                   highSchoolMan1+highSchoolMan2+highSchoolMan3+
	        		                   kindergartenGirl1+kindergartenGirl2+
	        		                   primaryEducationGirl1+primaryEducationGirl2+primaryEducationGirl3+
	        		                   primaryEducationGirl4+primaryEducationGirl5+primaryEducationGirl6+
	        		                   highSchoolGirl1+highSchoolGirl2+highSchoolGirl3	        		                   
	        		                   )%></td>          	                     
	           <td><%=formatter.format(sumKindergartenRoom+primaryEducationRoom+highShoolRoom)%></td>          	                     
	         </tr>
	       <% } %>           
           
           <tr align="right" bordercolor="#CCCCCC">
           	   <td align="center" colspan="2" bgcolor="#ADFF5B" style="color:#F00">รวมทั้งสิ้น</td>
           	   <td><%=formatter.format(sumKindergartenMan1)%></td>
           	   <td><%=formatter.format(sumKindergartenGirl1)%></td>           	   
           	   <td><%=formatter.format(sumKindergartenMan2)%></td>
           	   <td><%=formatter.format(sumKindergartenGirl2)%></td>           	   
           	   <td style="color:#F00"><%=formatter.format(sumKindergarten)%></td>
           	   <td><%=formatter.format(sumKindergartenRoom)%></td>
           	   
           	   <td><%=formatter.format(sumPrimaryEducationMan1)%></td>
           	   <td><%=formatter.format(sumPrimaryEducationGirl1)%></td>
           	   <td><%=formatter.format(sumPrimaryEducationMan2)%></td>
           	   <td><%=formatter.format(sumPrimaryEducationGirl2)%></td>
           	   <td><%=formatter.format(sumPrimaryEducationMan3)%></td>
           	   <td><%=formatter.format(sumPrimaryEducationGirl3)%></td>
           	   <td><%=formatter.format(sumPrimaryEducationMan4)%></td>
           	   <td><%=formatter.format(sumPrimaryEducationGirl4)%></td>
           	   <td><%=formatter.format(sumPrimaryEducationMan5)%></td>
           	   <td><%=formatter.format(sumPrimaryEducationGirl5)%></td>
           	   <td><%=formatter.format(sumPrimaryEducationMan6)%></td>
           	   <td><%=formatter.format(sumPrimaryEducationGirl6)%></td>
           	   <td style="color:#F00"><%=formatter.format(sumPrimaryEducation)%></td>
           	   <td><%=formatter.format(sumPrimaryEducationRoom)%></td>
           	   
           	  <td><%=formatter.format(sumHighSchoolMan1)%></td> 
           	  <td><%=formatter.format(sumHighSchoolGirl1)%></td> 
           	  <td><%=formatter.format(sumHighSchoolMan2)%></td> 
           	  <td><%=formatter.format(sumHighSchoolGirl2)%></td> 
           	  <td><%=formatter.format(sumHighSchoolMan3)%></td> 
           	  <td><%=formatter.format(sumHighSchoolGirl3)%></td> 
           	  <td style="color:#F00"><%=formatter.format(sumHighSchool)%></td> 
           	  <td><%=formatter.format(sumHighSchoolRoom)%></td> 
           	   
           	  <td><%=formatter.format(sumKindergartenMan1+sumKindergartenMan2+
           			                  sumPrimaryEducationMan1+sumPrimaryEducationMan2+sumPrimaryEducationMan3+
           			                  sumPrimaryEducationMan4+sumPrimaryEducationMan5+sumPrimaryEducationMan6+
           			                  sumHighSchoolMan1+sumHighSchoolMan2+sumHighSchoolMan3)%></td>
           	  <td><%=formatter.format(sumKindergartenGirl1+sumKindergartenGirl2+
           			                  sumPrimaryEducationGirl1+sumPrimaryEducationGirl2+sumPrimaryEducationGirl3+
           			                  sumPrimaryEducationGirl4+sumPrimaryEducationGirl5+sumPrimaryEducationGirl6+
           			                  sumHighSchoolGirl1+sumHighSchoolGirl2+sumHighSchoolGirl3)%></td>   
			 <td style="color:#F00"><%=formatter.format(sumKindergartenMan1+sumKindergartenMan2+
           			                  sumPrimaryEducationMan1+sumPrimaryEducationMan2+sumPrimaryEducationMan3+
           			                  sumPrimaryEducationMan4+sumPrimaryEducationMan5+sumPrimaryEducationMan6+
           			                  sumHighSchoolMan1+sumHighSchoolMan2+sumHighSchoolMan3+
           			                  sumKindergartenGirl1+sumKindergartenGirl2+
        			                  sumPrimaryEducationGirl1+sumPrimaryEducationGirl2+sumPrimaryEducationGirl3+
        			                  sumPrimaryEducationGirl4+sumPrimaryEducationGirl5+sumPrimaryEducationGirl6+
        			                  sumHighSchoolGirl1+sumHighSchoolGirl2+sumHighSchoolGirl3
           			                  )%></td>
             <td><%=formatter.format(sumKindergartenRoom+sumPrimaryEducationRoom+sumHighSchoolRoom)%></td>
 
           </tr>
				
       	</table>
       </div>
       <jsp:include page="footer.jsp"></jsp:include>
	</form>
</body>
</html>